home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / forth / pfe-0.000 / pfe-0 / pfe-0.9.13 / src / yours.c < prev   
Encoding:
C/C++ Source or Header  |  1995-07-17  |  3.7 KB  |  110 lines

  1. /*
  2.  * This file is part of the portable Forth environment written in ANSI C.
  3.  * Copyright (C) 1995  Dirk Uwe Zoller
  4.  *
  5.  * This library is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU Library General Public
  7.  * License as published by the Free Software Foundation; either
  8.  * version 2 of the License, or (at your option) any later version.
  9.  *
  10.  * This library is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13.  * See the GNU Library General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU Library General Public
  16.  * License along with this library; if not, write to the Free
  17.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  * This file is version 0.9.13 of 17-July-95
  20.  * Check for the latest version of this package via anonymous ftp at
  21.  *    roxi.rz.fht-mannheim.de:/pub/languages/forth/pfe-VERSION.tar.gz
  22.  * or    sunsite.unc.edu:/pub/languages/forth/pfe-VERSION.tar.gz
  23.  * or    ftp.cygnus.com:/pub/forth/pfe-VERSION.tar.gz
  24.  *
  25.  * Please direct any comments via internet to
  26.  *    duz@roxi.rz.fht-mannheim.de.
  27.  * Thank You.
  28.  */
  29. /*
  30.  * yours.c ---    This file is the place to add any additional primitives
  31.  *        you might wish.
  32.  *
  33.  * (duz 24Feb94)
  34.  *
  35.  *
  36.  * To make a new primitive Forth word, you have to write a C function of
  37.  * type
  38.  *
  39.  *    static void name_(void)
  40.  *
  41.  * Use the preprocessor macro
  42.  *
  43.  *    Code (name)
  44.  *
  45.  * to provide the prototype with the underscore appended to the
  46.  * name. The underscore helps to avoid name clashes with names and
  47.  * keywords of the C language.
  48.  *
  49.  * If you want to call such a primitive from C-source you must of
  50.  * course append the underscore to the name in the function call
  51.  * yourself. If you want to call it from another input file then you
  52.  * must leave out the `static' keyword in the function definition,
  53.  * which is what the alternative macro
  54.  *
  55.  *    code (name)
  56.  *
  57.  * does. Both are of course nothing but shortcuts to ease input of all
  58.  * those words.
  59.  *
  60.  * Having defined a primitive you must add it to the forth dictionary
  61.  * in order to make it visible to Forth.  At the end of each input
  62.  * file defining forth primitives you'll find a table declared with
  63.  * the macro
  64.  *
  65.  *    LISTWORDS (wordset_name) =
  66.  *    {
  67.  *      ...
  68.  *    };
  69.  *
  70.  * This declares a vector of some type and shows how to continue with
  71.  * the initialization of the vector.  Each vector element registers a
  72.  * forth word for loading into the dictionary at startup. In pfe the
  73.  * dictionary is not an initialized C structure but it is built from
  74.  * such structures -- like the one described here -- at startup.
  75.  *
  76.  * To enter words into this table there are several macros, all for
  77.  * brevity named with two uppercase letters. Using such a macro adds
  78.  * one more element to the list of initializers following the
  79.  * LISTWORDS declaration. Besides primitives you can enter variables
  80.  * and constants to the dictionary this way.
  81.  *
  82.  *    CO (NAME, c-name)    a primitive, not immediate
  83.  *    CI (NAME, c-name)    an immediate primitive
  84.  *    CS (NAME, c-name)    a primitive with separate execution
  85.  *                and compilation semantics, see examples
  86.  *                in core.c (if, case etc.) and macros in
  87.  *                compiler.h and -- good luck :-)
  88.  *    OV (NAME)        a normal variable
  89.  *    OC (NAME, value)    a normal constant
  90.  *    OL (NAME, value)    a normal value
  91.  *    IV (NAME)        an immediate variable
  92.  *    IC (NAME, value)    an immediate constant
  93.  *    IL (NAME, value)    an immediate value
  94.  */
  95.  
  96. #include "forth.h"
  97. #include "support.h"
  98.  
  99. Code (user_added_primitive)
  100. {
  101.   outs ("\nThis is a sample primitive."
  102.     " See src/yours.c for it's definition.\n");
  103. }
  104.  
  105. LISTWORDS (your) =
  106. {
  107.   CO ("USER-ADDED-PRIMITIVE", user_added_primitive),
  108. };
  109. COUNTWORDS (your, "Your kernel extensions");
  110.